import GradeModel from '../../model/GradeModel'
import ErrorHandlerCode from '../../utils/ErrorHandlerCode'
import BasicController from '../BasicController'

class StudentGradeController extends BasicController{
	addData(req,res){
        let orderHeader = req.body;
        GradeModel.add(orderHeader).then((data)=>{
            super.RequestSuccessMsg(res);
        }).catch((err)=>{
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}

	updateRecord(req,res){
        let orderHeader = req.body;
		GradeModel.update(orderHeader).then((data)=>{
			super.RequestSuccessMsg(res);
		}).catch((err)=>{
			res.json(ErrorHandlerCode.INNERSERVICERROR);
			throw err;
		})
	}

	deleteRecord(req, res){
        let orderHeader = req.body;
        GradeModel.delete(orderHeader.id).then((data) => {
            super.RequestSuccessMsg(res);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }

 	findById(req, res){
        let orderHeader = req.body;
        GradeModel.findById(orderHeader.sno).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    
    findByPage(req, res){
        let orderHeader = req.body.a;
        orderHeader.page_size = orderHeader.page_size || 10;
        orderHeader.page_no = orderHeader.page_no || 1;
        
        GradeModel.findByPage(req.body).then((data) => {
            data.page_no = orderHeader.page_no;
            data.page_size = orderHeader.page_size;
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    
    findAll(req, res){
        let orderHeader = req.body;
        GradeModel.findAllData(orderHeader).then((data) => {
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
}

module.exports = new StudentGradeController();